package com.rzjm.exercise.common.log;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.rzjm.exercise.sys.core.log.service.LogService;

@Component
public class LogConsumer {
	private static final int MAX_INSERT_SIZE = 50;
	@Autowired
	private LogService sysLogService;

	@Scheduled(fixedDelay = 1000)
	public void consume() {
		LogQueue queue = LogQueue.INSTANCE;

		if (queue.size() >= MAX_INSERT_SIZE) {
			sysLogService.saveBatch(queue.pollList(), MAX_INSERT_SIZE);
        }
	}
}
